



//
//  NQiyeSumViewController.m
//  nncloud
//
//  Created by macfai on 2018/12/12.
//  Copyright © 2018 macfai. All rights reserved.
//
#import "NEnterpriseSearchVC.h"
#import "NQiyeSumViewController.h"
#import "NMyQiyeModel.h"
#import "NZhaopinCell.h"
#import "NMyQiyeViewController.h"
@interface NQiyeSumViewController ()<UITableViewDataSource,UITableViewDelegate,STPickerSingleDelegate>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@property(nonatomic,strong)NSArray *titleArray;

@property(nonatomic,strong)NSArray *pickerArray;

@property (nonatomic,assign)NSInteger index;

@property (nonatomic,strong)NSDictionary *paraDict;

//@property (nonatomic,strong)STPickerSingle *picker;

@end

@implementation NQiyeSumViewController
#define cellIdentifier @"zhaopin"
#define SectionHeaderHeight  10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 115.f;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NZhaopinCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        _tableView.showsVerticalScrollIndicator = NO;
        //        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;

    if ([self.flag isEqualToString:@"search"]) {
        
        [self.navigationItem setItemWithTitle:@"搜索结果" textColor:kNavigationTitleColor fontSize:18 itemType:center];
        
   
    }else{
        
        [self.navigationItem setItemWithTitle:@"工业企业汇总" textColor:kNavigationTitleColor fontSize:18 itemType:center];
        [self addNavgationRightButtonWithFrame:CGRectMake(0, 0, 40, 40) title:@"" Image:@"搜索" selectedIMG:nil tartget:self action:@selector(search)];
       
    }
    self.dataArray = [NSMutableArray array];
    [self.view addSubview:self.tableView];
    [self loadData];
}

///搜索
- (void)search{
//    WeakStament(ws);
    NEnterpriseSearchVC *ser = [NEnterpriseSearchVC new];
    [self.navigationController pushViewController:ser animated:YES];
//    ser.parablock = ^(NSDictionary * _Nonnull dict) {
//        YYLog(@"%@",dict);
//        //进行数据请求
//        self.paraDict = dict;
//        //拿到参数进行数据请求
//        [ws loadData];
//    };
//
//    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:ser];
//    [self presentViewController:nav animated:YES completion:nil];
//    [self.navigationController pushViewController:ser animated:YES];
}

- (void)loadData{
    //参数拼接
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    //字典遍历，将一个字典的key value 赋给另一个字典
    [self.paraDict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        [dict setObject:obj forKey:key];
    }];
    
    [dict setObject:@100 forKey:@"size"];
    [dict setObject:@1 forKey:@"curPage"];
//    NSDictionary *dic = self.paraDict?:@{@"size":@100,@"curPage":@1};
    [[NNRCNetRequest manager]getWithUrl:kQiyeListUrl params:dict success:^(id result) {
        YYLog(@"%@",result);
        WeakStament(ws);
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            NSArray *arr = result[@"page"][@"records"];
            YYLog(@"%@",arr);
            for (NSDictionary *dict in arr) {
                NMyQiyeModel *model = [NMyQiyeModel mj_objectWithKeyValues:dict];
                [ws.dataArray addObject:model];
            }
            [ws.tableView reloadData];
        }else{
            [AFToast showText:result[@"msg"]];
        }
    } failure:^(id failure) {
        
    }];
}

#pragma mark - datasource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return  self.dataArray.count;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NMyQiyeModel*model = self.dataArray[indexPath.section];
    NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.name.font = [UIFont boldSystemFontOfSize:15];
    cell.salary.hidden = YES;
    cell.qModel = model;
    return cell;
}

#pragma mark - delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NMyQiyeModel *model = self.dataArray[indexPath.section];
    NMyQiyeViewController *myQi = [NMyQiyeViewController new];
    myQi.eid = model.enterpriseId;
    myQi.userType = [NUserModel shareInstance].userInfoType;
    [self.navigationController pushViewController:myQi animated:YES];
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}




@end
